
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
*
*
* @author Jon Doe
*/
public class mathExam01 {
	/**
	*
	*
	* @author Jon Doe
	*/	
	public static void main(final String[] args)  throws Exception{ // NOPMD by jun on 20-6-3 下午5:39
		/**
		*
		*
		* @author Jon Doe
		*/
		//输入：第一个参数是nnnn，表示n道题；第二个参数是grade，表示几年级
		final int nnnn = Integer.parseInt(args[0]);
		final String grade = args[1];
     if (args.length == 1) {
		show1(Integer.valueOf(args[0]));
	} else {
		switch (grade) {
		case "1":
			show1(nnnn);
			break;
		case "2":
			show2(nnnn);
			break;

		default:
			System.out.println("第二个参数错误，请重新运行，输入1~2的年级数，例如:1"); // NOPMD by jun on 20-6-5 上午9:09
//			log.fine("Entering test");
			break;
		}
	}
}

	/**
	*
	*
	* @author Jon Doe
	*/
	public static void show1(final int nnnnn) throws IOException {	 // NOPMD by jun on 20-6-5 上午9:01
 
//		BufferedWriter file1 = Files.newBufferedWriter(Paths.get("out.txt"), StandardCharsets.UTF_8);
		BufferedWriter file1 = new BufferedWriter(new FileWriter("out.txt"));
		
       String [] arry =  new String[nnnnn+1];
       int [] answer =new int[nnnnn+1]; 	   
      //随机产生x的值：0或1，0执行加法，1执行减法。
      //x1和x2的取值范围是[0，100）的整数；如果x1+x2的值大于100，则x1和x2各减50
      //输出x1+x2的值
      for (int i = 1; i < nnnnn+1; i++) {  
    	final int xxxx=0+(int)(Math.random()*2);
        int xxxx1=0+(int)(Math.random()*100);
    	int xxxx2=0+(int)(Math.random()*100);	 
        if(xxxx==0) {      	       	 
           if((xxxx1+xxxx2)>100) {
        	  if(xxxx1>50) xxxx1=xxxx1-50;
        	  if(xxxx2>50) xxxx2=xxxx2-50;
           }
        	  arry[i]="("+ i +") "+ xxxx1+" + "+xxxx2+" = ";
        	  answer[i]=xxxx1+xxxx2;
           	  //将arry[i]写入out6729.txt文件
        	  file1.write(arry[i]);	
        	  file1.newLine();			
			  //System.out.println(arry[i]);			
        }
        //如果x1<x2,则两个值对换；
        //输出x1-x2的值
        else{  	
        	 if(xxxx1<xxxx2)
	 	        {int ttttt=0;ttttt=xxxx1;xxxx1=xxxx2;xxxx2=ttttt;}
        	arry[i]= "("+ i +") "+xxxx1+" - "+xxxx2+" = ";
        	answer[i]=xxxx1-xxxx2;
        	file1.write(arry[i]);	
        	file1.newLine();
			//System.out.println(arry[i]);
        }     	  
      }
      //System.out.println("--------标准答案-------");     
      file1.write("--------标准答案--------");
      file1.newLine();
		   
	         for (int a = 1; a<nnnnn+1; a++) {
	        	final String str=arry[a]+answer[a];
	        	file1.write(str);
				//写入一个行分隔符。
	        	file1.newLine();
				//System.out.println(str);
	         }
	         final Date date = new Date();
	         final SimpleDateFormat qqqqq = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");	  
	         file1.write("211906729邱江斌"+" "+qqqqq.format(date));
	         //System.out.println("211906729邱江斌"+" "+q.format(date));
	         file1.close();    
 }
	public static void show2(final int n) throws Exception{ // NOPMD by jun on 20-6-3 下午5:39
//		final BufferedWriter file2 = Files.newBufferedWriter(Paths.get("out.txt"), StandardCharsets.UTF_8);
		BufferedWriter file2 = new BufferedWriter(new FileWriter("out.txt"));
	       String [] arry =  new String[n+1];
	       String[] answer =new String[n+1];     	 	      
	      for (int i = 1; i < n+1; i++) { 
	    	//随机产生x的值：0或1，0执行乘法，1执行除法。
	    	final int xxxxx=0+(int)(Math.random()*2);
	        
	        //执行乘法
	    	if(xxxxx==0) {      	       	 
	    		final int xxxxx1=0+(int)(Math.random()*50);
		    	final int xxxxx2=0+(int)(Math.random()*50);	 
	        	  arry[i]="("+ i +") "+ xxxxx1+" x "+xxxxx2+" = ";
	        	  answer[i]=Integer.toString(xxxxx1*xxxxx2);
	           	  //将arry[i]写入out6729.txt文件
	        	  file2.write(arry[i]);	
	        	  file2.newLine();			
				  //System.out.println(arry[i]);			
	        }
	        //执行除法
	        else{  	
	        	final int xxxxx1=0+(int)(Math.random()*100);
		    	final int xxxxx2=1+(int)(Math.random()*10);	 	        	
	        	
	        	arry[i]= "("+ i +") "+xxxxx1+" ÷ "+xxxxx2+" = ";	        	
	        	answer[i]=xxxxx1/xxxxx2+"..."+(xxxxx1%xxxxx2);
	        	file2.write(arry[i]);	
	        	file2.newLine();
				//System.out.println(arry[i]);
	        	}    	       	  
	      }
	      //System.out.println("--------标准答案-------");     
	      file2.write("--------标准答案--------");
	      file2.newLine();
			   
		         for (int a = 1; a<n+1; a++) {		         
		        	final String str=arry[a]+answer[a];
		        	file2.write(str);
		        	file2.newLine();
					//System.out.println(str);
		         }
		         final Date date = new Date();
		         SimpleDateFormat qqqqq = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");	  
		         file2.write("211906729邱江斌"+" "+qqqqq.format(date));
		         //System.out.println("211906729邱江斌"+" "+q.format(date));
		         file2.close();   

	}
}




